
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>RSoftTools &#8212; RSoft 1.0 documentation</title>
    <link rel="stylesheet" href="../_static/classic.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">RSoft 1.0 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Module code</a> &#187;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <h1>Source code for RSoftTools</h1><div class="highlight"><pre>
<span></span><span class="c1"># =*= coding: utf-8 -*-</span>
<span class="sd">&quot;&quot;&quot;RSoftTools</span>
<span class="sd">Created on 8 November 2018</span>
<span class="sd">@author: Robert Ivancic</span>

<span class="sd">This module was created to facilitate easy creation of softness</span>
<span class="sd">fields based on current methodologies. </span>

<span class="sd">Notes</span>
<span class="sd">-----</span>
<span class="sd">  </span>

<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">from</span> <span class="nn">netCDF4</span> <span class="k">import</span> <span class="n">Dataset</span>
<span class="kn">from</span> <span class="nn">LammpsIO</span> <span class="k">import</span> <span class="n">NetCDFIO</span>
<span class="kn">import</span> <span class="nn">sklearn</span> <span class="k">as</span> <span class="nn">skl</span>
<span class="kn">from</span> <span class="nn">sklearn</span> <span class="k">import</span> <span class="n">svm</span>

<div class="viewcode-block" id="RSoft"><a class="viewcode-back" href="../RSoftTools.html#RSoftTools.RSoft">[docs]</a><span class="k">class</span> <span class="nc">RSoft</span><span class="p">:</span>
  <span class="sd">&quot;&quot;&quot;RSoft package for python.</span>

<span class="sd">  This class is made to deal with and generate RSoftSF and RSoftPlane</span>
<span class="sd">  files.</span>

<span class="sd">  Attributes</span>
<span class="sd">  ----------</span>
<span class="sd">  etol_radial : float</span>
<span class="sd">    \epsilon_R</span>

<span class="sd">    Radial error tolerance (if available). Can obtain after OpenSFI.</span>
<span class="sd">  mus : numpy array (n_SF_rad)</span>
<span class="sd">    Mu structure function parameters (if available). Can obtain after</span>
<span class="sd">    OpenSFI used.</span>
<span class="sd">  radial_Xs : numpy int array (n_SF_rad)</span>
<span class="sd">    Radial_X structure function parameters (if available). Can obtain</span>
<span class="sd">    after OpenSFI used.</span>
<span class="sd">  radial_Ys : numpy int array (n_SF_rad)</span>
<span class="sd">    Radial_Y structure function parameters (if available). Can obtain</span>
<span class="sd">    after OpenSFI used.</span>
<span class="sd">  etol_angular : float</span>
<span class="sd">    Angular error tolerance (if available). Can obtain after OpenSFI.</span>
<span class="sd">  xis : numpy array (n_SF_ang)</span>
<span class="sd">    Xi structure function parameters (if available). Can obtain after</span>
<span class="sd">    OpenSFI used.</span>
<span class="sd">  lambdas : numpy int array (n_SF_ang)</span>
<span class="sd">    Lambda structure function parameters (if available). Can obtain</span>
<span class="sd">    after OpenSFI used.</span>
<span class="sd">  zetas : numpy int array (n_SF_ang)</span>
<span class="sd">    Zeta structure function parameters (if available). Can obtain</span>
<span class="sd">    after OpenSFI used.</span>
<span class="sd">  angular_Xs : numpy int array (n_SF_ang)</span>
<span class="sd">    Angular_X structure function parameters (if available). Can obtain</span>
<span class="sd">    after OpenSFI used.</span>
<span class="sd">  angular_Ys : numpy int array (n_SF_ang)</span>
<span class="sd">    Angular_Y structure function parameters (if available). Can obtain</span>
<span class="sd">    after OpenSFI used.</span>
<span class="sd">  angular_Zs : numpy int array (n_SF_ang)</span>
<span class="sd">    Angular_Z structure function parameters (if available). Can obtain</span>
<span class="sd">    after OpenSFI used.</span>
<span class="sd">  training_R : list (n_type) of numpy int array (n_eg_type, 2)</span>
<span class="sd">    Python list containing a numpy array containing the frame and </span>
<span class="sd">    particle id (respectively) for each rearranging training example</span>
<span class="sd">    for each type of particle. Can obtain after SelectTrainingSet</span>
<span class="sd">    is used.</span>
<span class="sd">  training_NR : list (n_type) of numpy int array (n_eg_type, 2)</span>
<span class="sd">    Python list containing a numpy array containing the frame and </span>
<span class="sd">    particle id (respectively) for each non-rearranging training</span>
<span class="sd">    example for each type of particle. Can obtain after </span>
<span class="sd">    SelectTrainingSet is used.</span>


<span class="sd">  &quot;&quot;&quot;</span>

  <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="c1"># Initializes private variables</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__containsRadial</span> <span class="o">=</span> <span class="kc">False</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__containsAngular</span> <span class="o">=</span> <span class="kc">False</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__containsParticles</span> <span class="o">=</span> <span class="kc">False</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__n_SF_ang</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__n_SF_rad</span> <span class="o">=</span> <span class="mi">0</span>

    <span class="c1"># Checks if public functions have been used</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__openSFI</span> <span class="o">=</span> <span class="kc">False</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__openSFO</span> <span class="o">=</span> <span class="kc">False</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__openPlaneI</span> <span class="o">=</span> <span class="kc">False</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__openPlaneO</span> <span class="o">=</span> <span class="kc">False</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__openDynamicsI</span> <span class="o">=</span> <span class="kc">False</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__selectTrainingSet</span> <span class="o">=</span> <span class="kc">False</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__train</span> <span class="o">=</span> <span class="kc">False</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__getRadial</span> <span class="o">=</span> <span class="kc">False</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__getAngular</span> <span class="o">=</span> <span class="kc">False</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__setRadial</span> <span class="o">=</span> <span class="kc">False</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__setAngular</span> <span class="o">=</span> <span class="kc">False</span>

    <span class="c1"># SoftPlane global variable initialization</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__close</span> <span class="o">=</span> <span class="kc">False</span>

<div class="viewcode-block" id="RSoft.OpenSFO"><a class="viewcode-back" href="../RSoftTools.html#RSoftTools.RSoft.OpenSFO">[docs]</a>  <span class="k">def</span> <span class="nf">OpenSFO</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">nc_file_name</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Opens RSoftSF file</span>
<span class="sd">    </span>
<span class="sd">    Opens a RSoftSF file of nc_file_name for writing (output).</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    nc_file_name : str</span>
<span class="sd">      Name of RSoftSF file you wish to write to.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># Checks errors</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__openSFO</span><span class="p">:</span>
      <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: Cannot use OpenSFO twice&#39;</span><span class="p">)</span>
      <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__openPlaneO</span><span class="p">:</span>
      <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: Cannot use OpenPlaneO and OpenSFO&#39;</span><span class="p">)</span>
      <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>

    <span class="c1"># Opens RSoftSF and initializes values</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span> <span class="o">=</span> <span class="n">Dataset</span><span class="p">(</span><span class="n">nc_file_name</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">,</span> <span class="nb">format</span><span class="o">=</span><span class="s1">&#39;NETCDF4&#39;</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">Conventions</span> <span class="o">=</span> <span class="s1">&#39;RSoftSF&#39;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">ConventionVersion</span> <span class="o">=</span> <span class="s1">&#39;1.0&#39;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__SetSFParams</span><span class="p">()</span>

    <span class="c1"># Marks function as run</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__openSFO</span> <span class="o">=</span> <span class="kc">True</span>

    <span class="c1"># Allows for chained statements</span>
    <span class="k">return</span> <span class="bp">self</span></div>

<div class="viewcode-block" id="RSoft.OpenPlaneO"><a class="viewcode-back" href="../RSoftTools.html#RSoftTools.RSoft.OpenPlaneO">[docs]</a>  <span class="k">def</span> <span class="nf">OpenPlaneO</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">nc_file_name</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Opens RSoftPlane file</span>
<span class="sd">    </span>
<span class="sd">    Opens a RSoftPlane file of nc_file_name for writing (output).</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    nc_file_name : str</span>
<span class="sd">      Name of RSoftPlane file you wish to write to.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># Checks errors</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__openPlaneO</span><span class="p">:</span>
      <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: Cannot use OpenPlaneO twice&#39;</span><span class="p">)</span>
      <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__openSFO</span><span class="p">:</span>
      <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: Cannot use OpenSFO and OpenPlaneO&#39;</span><span class="p">)</span>
      <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>

    <span class="c1"># Opens RSoftPlane and initializes values</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span> <span class="o">=</span> <span class="n">Dataset</span><span class="p">(</span><span class="n">nc_file_name</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">,</span> <span class="nb">format</span><span class="o">=</span><span class="s1">&#39;NETCDF4&#39;</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">Conventions</span> <span class="o">=</span> <span class="s1">&#39;RSoftPlane&#39;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">ConventionVersion</span> <span class="o">=</span> <span class="s1">&#39;1.0&#39;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__SetSFParams</span><span class="p">()</span>

    <span class="c1"># Marks function as run</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__openPlaneO</span> <span class="o">=</span> <span class="kc">True</span>

    <span class="c1"># Allows for chained statements</span>
    <span class="k">return</span> <span class="bp">self</span></div>

<div class="viewcode-block" id="RSoft.OpenSFI"><a class="viewcode-back" href="../RSoftTools.html#RSoftTools.RSoft.OpenSFI">[docs]</a>  <span class="k">def</span> <span class="nf">OpenSFI</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">nc_file_name</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Opens RSoftSF file</span>
<span class="sd">    </span>
<span class="sd">    Opens a RSoftSF file of nc_file_name for reading (input).</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    nc_file_name : str</span>
<span class="sd">      Name of RSoftSF file you wish to read from.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># Checks errors</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__openSFI</span><span class="p">:</span>
      <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: Cannot use OpenSFI twice&#39;</span><span class="p">)</span>
      <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__openPlaneI</span><span class="p">:</span>
      <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: Cannot use OpenSFI and OpenPlaneI together&#39;</span><span class="p">)</span>
      <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>

    <span class="c1"># Opens RSoftSF and initializes values</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span> <span class="o">=</span> <span class="n">Dataset</span><span class="p">(</span><span class="n">nc_file_name</span><span class="p">,</span> <span class="s1">&#39;r&#39;</span><span class="p">,</span> <span class="nb">format</span><span class="o">=</span><span class="s1">&#39;NETCDF4&#39;</span><span class="p">)</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span><span class="o">.</span><span class="n">Conventions</span> <span class="o">!=</span> <span class="s1">&#39;RSoftSF&#39;</span><span class="p">:</span>
      <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: OpenSFI can only load RSoftSF files&#39;</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__GetSFParams</span><span class="p">()</span>
    <span class="n">dim_names</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span><span class="o">.</span><span class="n">dimensions</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
    <span class="k">if</span> <span class="s1">&#39;frame&#39;</span> <span class="ow">in</span> <span class="n">dim_names</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">__containsParticles</span> <span class="o">=</span> <span class="kc">True</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__openSFO</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">__openPlaneO</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">__SetSFParams</span><span class="p">()</span>

    <span class="c1"># Error messages</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__openDynamicsI</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">__containsParticles</span><span class="p">:</span>
      <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_n_f</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span><span class="o">.</span><span class="n">dimensions</span><span class="p">[</span><span class="s1">&#39;frame&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">size</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: n_f for RSoftSF and AMBER file are equal.&#39;</span><span class="p">)</span>
        <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
      <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_n_p</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span><span class="o">.</span><span class="n">dimensions</span><span class="p">[</span><span class="s1">&#39;atom&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">size</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: n_p for RSoftSF and AMBER file are equal.&#39;</span><span class="p">)</span>
        <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>

    <span class="c1"># Obtains number of types of particles to make planes for</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__types</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">radial_Xs</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">angular_Xs</span><span class="p">))</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__types_unique</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">unique</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__types</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__n_type</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__types_unique</span><span class="p">)</span>

    <span class="c1"># Marks function as run</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__openSFI</span> <span class="o">=</span> <span class="kc">True</span>

    <span class="c1"># Allows for chained statements</span>
    <span class="k">return</span> <span class="bp">self</span></div>

  <span class="k">def</span> <span class="nf">__GetSFParams</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Gets structure function parameters from nc_RSoft_I</span>

<span class="sd">    Reads all of the parameters used to calculate structure functions</span>
<span class="sd">    from an RSoftPlane or RSoftSF file.</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">dim_names</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span><span class="o">.</span><span class="n">dimensions</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
    <span class="k">if</span> <span class="s1">&#39;radial_structure_functions&#39;</span> <span class="ow">in</span> <span class="n">dim_names</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">__containsRadial</span> <span class="o">=</span> <span class="kc">True</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">__n_SF_rad</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;mus&#39;</span><span class="p">][:])</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">etol_radial</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span><span class="o">.</span><span class="n">radial_error_tolerance</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">mus</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;mus&#39;</span><span class="p">][:]</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">Ls</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;Ls&#39;</span><span class="p">][:]</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">radial_Xs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;radial_Xs&#39;</span><span class="p">][:]</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">radial_Ys</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;radial_Ys&#39;</span><span class="p">][:]</span>
    <span class="k">if</span> <span class="s1">&#39;angular_structure_functions&#39;</span> <span class="ow">in</span> <span class="n">dim_names</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">__containsAngular</span> <span class="o">=</span> <span class="kc">True</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">etol_angular</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span><span class="o">.</span><span class="n">angular_error_tolerance</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">__n_SF_ang</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;xis&#39;</span><span class="p">][:])</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">xis</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;xis&#39;</span><span class="p">][:]</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">zetas</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;zetas&#39;</span><span class="p">][:]</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">lambdas</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;lambdas&#39;</span><span class="p">][:]</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">angular_Xs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;angular_Xs&#39;</span><span class="p">][:]</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">angular_Ys</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;angular_Ys&#39;</span><span class="p">][:]</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">angular_Zs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;angular_Zs&#39;</span><span class="p">][:]</span>

  <span class="k">def</span> <span class="nf">__SetSFParams</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Sets structure function parameters to nc_RSoft_O</span>

<span class="sd">    Writes all of the parameters used to calculate structure functions</span>
<span class="sd">    to an RSoftPlane or RSoftSF file.</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="c1"># If radial structure functions are in output</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__containsRadial</span><span class="p">:</span>
      <span class="c1"># Defines radial attributes</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">radial_error_tolerance</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">etol_radial</span>

      <span class="c1"># Defines radial dimensions</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s1">&#39;radial_structure_functions&#39;</span><span class="p">,</span>\
            <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mus</span><span class="p">))</span>

      <span class="c1"># Defines radial variables</span>
      <span class="n">mus_var_id_O</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;mus&#39;</span><span class="p">,</span> \
            <span class="s1">&#39;f4&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;radial_structure_functions&#39;</span><span class="p">))</span>
      <span class="n">Ls_var_id_O</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;Ls&#39;</span><span class="p">,</span> \
            <span class="s1">&#39;f4&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;radial_structure_functions&#39;</span><span class="p">))</span>
      <span class="n">radial_Xs_var_id_O</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span>\
            <span class="s1">&#39;radial_Xs&#39;</span><span class="p">,</span> <span class="s1">&#39;i4&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;radial_structure_functions&#39;</span><span class="p">))</span>
      <span class="n">radial_Ys_var_id_O</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span>\
            <span class="s1">&#39;radial_Ys&#39;</span><span class="p">,</span> <span class="s1">&#39;i4&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;radial_structure_functions&#39;</span><span class="p">))</span>

      <span class="c1"># Sets radial structure function variables</span>
      <span class="n">mus_var_id_O</span><span class="p">[:]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mus</span>
      <span class="n">Ls_var_id_O</span><span class="p">[:]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">Ls</span>
      <span class="n">radial_Xs_var_id_O</span><span class="p">[:]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">radial_Xs</span>
      <span class="n">radial_Ys_var_id_O</span><span class="p">[:]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">radial_Ys</span>

    <span class="c1"># If angular structure functions are in output</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__containsAngular</span><span class="p">:</span>
      <span class="c1"># Defines angular attributes</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">angular_error_tolerance</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">etol_angular</span>

      <span class="c1"># Defines angular dimensions</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s1">&#39;angular_structure_functions&#39;</span><span class="p">,</span>\
            <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">xis</span><span class="p">))</span>

      <span class="c1"># Defines angular variables</span>
      <span class="n">xis_var_id_O</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;xis&#39;</span><span class="p">,</span> \
            <span class="s1">&#39;f4&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;angular_structure_functions&#39;</span><span class="p">))</span>
      <span class="n">zetas_var_id_O</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;zetas&#39;</span><span class="p">,</span> \
            <span class="s1">&#39;i4&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;angular_structure_functions&#39;</span><span class="p">))</span>
      <span class="n">lambdas_var_id_O</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;lambdas&#39;</span><span class="p">,</span> \
            <span class="s1">&#39;i4&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;angular_structure_functions&#39;</span><span class="p">))</span>
      <span class="n">angular_Xs_var_id_O</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span>\
            <span class="s1">&#39;angular_Xs&#39;</span><span class="p">,</span> <span class="s1">&#39;i4&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;angular_structure_functions&#39;</span><span class="p">))</span>
      <span class="n">angular_Ys_var_id_O</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span>\
            <span class="s1">&#39;angular_Ys&#39;</span><span class="p">,</span> <span class="s1">&#39;i4&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;angular_structure_functions&#39;</span><span class="p">))</span>
      <span class="n">angular_Zs_var_id_O</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span>\
            <span class="s1">&#39;angular_Zs&#39;</span><span class="p">,</span> <span class="s1">&#39;i4&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;angular_structure_functions&#39;</span><span class="p">))</span>    

      <span class="c1"># Sets angular structure function variables</span>
      <span class="n">xis_var_id_O</span><span class="p">[:]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">xis</span>
      <span class="n">zetas_var_id_O</span><span class="p">[:]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">zetas</span>
      <span class="n">lambdas_var_id_O</span><span class="p">[:]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">lambdas</span>
      <span class="n">angular_Xs_var_id_O</span><span class="p">[:]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">angular_Xs</span>
      <span class="n">angular_Ys_var_id_O</span><span class="p">[:]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">angular_Ys</span>
      <span class="n">angular_Zs_var_id_O</span><span class="p">[:]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">angular_Zs</span>


<div class="viewcode-block" id="RSoft.OpenDynamicsI"><a class="viewcode-back" href="../RSoftTools.html#RSoftTools.RSoft.OpenDynamicsI">[docs]</a>  <span class="k">def</span> <span class="nf">OpenDynamicsI</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">nc_file_name</span><span class="p">,</span> <span class="n">dynamics_name</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Opens dynamic file in AMBER (netCDF) file format</span>
<span class="sd">    </span>
<span class="sd">    Opens an AMBER molecular dynamics file. This file must have a data</span>
<span class="sd">    column named dynamics_name. This data column should contain p_hop </span>
<span class="sd">    or D^2_min data to classify rearrangements or non-rearrangements in</span>
<span class="sd">    the system.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    nc_file_name : str</span>
<span class="sd">      Name of AMBER file you wish to read from.</span>
<span class="sd">    dynamics_name : str</span>
<span class="sd">      Name of dynamics data column</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="c1"># Checks errors</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__openDynamicsI</span><span class="p">:</span>
      <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: Cannot use OpenDynamicI twice&#39;</span><span class="p">)</span>
      <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>


    <span class="c1"># Opens AMBER file and checks for dynamics_name</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__NcIO_dyn</span> <span class="o">=</span> <span class="n">NetCDFIO</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__NcIO_dyn</span><span class="o">.</span><span class="n">OpenI</span><span class="p">(</span><span class="n">nc_file_name</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">_n_p</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__NcIO_dyn</span><span class="o">.</span><span class="n">NumParts</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">_n_f</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__NcIO_dyn</span><span class="o">.</span><span class="n">NumFrames</span><span class="p">()</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">__NcIO_dyn</span><span class="o">.</span><span class="n">GetDataCol</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">dynamics_name</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">__dynamics_name</span> <span class="o">=</span> <span class="n">dynamics_name</span>
    <span class="k">except</span><span class="p">:</span>
      <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: </span><span class="se">\&#39;</span><span class="s1">&#39;</span><span class="o">+</span><span class="n">dynamics_name</span><span class="o">+</span><span class="s1">&#39;</span><span class="se">\&#39;</span><span class="s1"> data column is not in &#39;</span><span class="p">)</span>
      <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;      &#39;</span><span class="o">+</span><span class="n">nc_file_name</span><span class="p">)</span>
      <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
    <span class="k">try</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">__NcIO_dyn</span><span class="o">.</span><span class="n">GetDataCol</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="s1">&#39;type&#39;</span><span class="p">)</span>
    <span class="k">except</span><span class="p">:</span>
      <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: </span><span class="se">\&#39;</span><span class="s1">type</span><span class="se">\&#39;</span><span class="s1"> data column is not in &#39;</span> <span class="o">+</span> <span class="n">nc_file_name</span><span class="p">)</span>
      <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>

    <span class="c1"># Error messages</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__openSFI</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">__containsParticles</span><span class="p">:</span>
      <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_n_f</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span><span class="o">.</span><span class="n">dimensions</span><span class="p">[</span><span class="s1">&#39;frame&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">size</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: n_f for RSoftSF and AMBER file are equal.&#39;</span><span class="p">)</span>
        <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
      <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_n_p</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span><span class="o">.</span><span class="n">dimensions</span><span class="p">[</span><span class="s1">&#39;atom&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">size</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: n_p for RSoftSF and AMBER file are equal.&#39;</span><span class="p">)</span>
        <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>

    <span class="c1"># Marks function as run</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__openDynamicsI</span> <span class="o">=</span> <span class="kc">True</span>

    <span class="c1"># Allows for chained statements</span>
    <span class="k">return</span> <span class="bp">self</span></div>

<div class="viewcode-block" id="RSoft.Train"><a class="viewcode-back" href="../RSoftTools.html#RSoftTools.RSoft.Train">[docs]</a>  <span class="k">def</span> <span class="nf">Train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">n_eg</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">K</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> \
          <span class="n">C_parameters</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.01</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">,</span> <span class="mf">10.</span><span class="p">,</span> <span class="mf">100.</span><span class="p">]),</span> \
          <span class="n">norm_SF</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">norm_plane</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">tol_</span><span class="o">=</span><span class="mf">0.0001</span><span class="p">,</span> \
          <span class="n">max_iter_</span><span class="o">=</span><span class="mi">10000</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Trains a softness hyperplane</span>

<span class="sd">    Trains a softness hyperplane for all species given an RSoftSF file</span>
<span class="sd">    and an AMBER molecular dynamics file containing dynamics_name</span>
<span class="sd">    data column.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    n_eg : numpy int array (n_types), optional</span>
<span class="sd">      Numpy array with number of rearranging training examples to </span>
<span class="sd">      include for each type. If not set, assumes this to be maximum</span>
<span class="sd">      number which meets all other criteria</span>
<span class="sd">    K : int, optional</span>
<span class="sd">      Positive integer of folds for K-folds cross-validation to chooose</span>
<span class="sd">      optimal penalty parameter. K = 5 is used by default.</span>
<span class="sd">    C_parameters : numpy array, optional</span>
<span class="sd">      Numpy array of penalty parameters to test during </span>
<span class="sd">      cross-validation. Values 0.01, 0.1, 1, 10, and 100 are default</span>
<span class="sd">      values to check.</span>
<span class="sd">    norm_SF : boolean, optional</span>
<span class="sd">      Whether to normalize structure functions before running linear</span>
<span class="sd">      SVM. This typically leads to better fits. If true, we subtract</span>
<span class="sd">      the mean and divide by the STDev of all structure functions. If</span>
<span class="sd">      not set, default is True.</span>
<span class="sd">    norm_plane : boolean, optional</span>
<span class="sd">      Ensures the standard deviation of softness is 1. If not set,</span>
<span class="sd">      default is true.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># ERROR messages</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__openSFI</span><span class="p">:</span>
      <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: Must use OpenSFI before Train&#39;</span><span class="p">)</span>
      <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__containsParticles</span><span class="p">:</span>
      <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: RSoftSF file must contain particles&#39;</span><span class="p">)</span>
      <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__openDynamicsI</span><span class="p">:</span>
      <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: Must use OpenDynamicsI before Train&#39;</span><span class="p">)</span>
      <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__selectTrainingSet</span><span class="p">:</span>
      <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: Must use SelectTrainingSet before Train&#39;</span><span class="p">)</span>
      <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>

    <span class="c1"># Initialize outputs</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">radial_plane</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">__n_type</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">__n_SF_rad</span><span class="p">))</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">angular_plane</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">__n_type</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">__n_SF_ang</span><span class="p">))</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">intercept</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__n_type</span><span class="p">)</span>
    <span class="n">n_SF</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__n_SF_rad</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">__n_SF_ang</span>

    <span class="c1"># Initialization of structure function and plane norms</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__train</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">__InitializeNorms</span><span class="p">(</span><span class="n">norm_SF</span><span class="p">,</span> <span class="n">norm_plane</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">norm_SF</span><span class="p">:</span>
      <span class="n">mean_SF</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_mean_SF</span>
      <span class="n">std_SF</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_std_SF</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">mean_SF</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_SF</span><span class="p">)</span>
      <span class="n">std_SF</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="n">n_SF</span><span class="p">)</span>

    <span class="c1"># For each particle type</span>
    <span class="k">for</span> <span class="n">idx_type</span><span class="p">,</span> <span class="n">type_</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__types_unique</span><span class="p">):</span>
      <span class="c1"># Initializes model and grid search</span>
      <span class="n">linear_svm</span> <span class="o">=</span> <span class="n">svm</span><span class="o">.</span><span class="n">LinearSVC</span><span class="p">(</span>\
            <span class="n">dual</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">tol</span><span class="o">=</span><span class="n">tol_</span><span class="p">,</span> <span class="n">max_iter</span><span class="o">=</span><span class="n">max_iter_</span><span class="p">)</span>
      <span class="n">grid_search</span> <span class="o">=</span> <span class="n">skl</span><span class="o">.</span><span class="n">model_selection</span><span class="o">.</span><span class="n">GridSearchCV</span><span class="p">(</span><span class="n">linear_svm</span><span class="p">,</span>
            <span class="n">param_grid</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;C&#39;</span><span class="p">:</span><span class="n">C_parameters</span><span class="p">},</span> <span class="n">cv</span><span class="o">=</span><span class="n">K</span><span class="p">,</span>
            <span class="n">refit</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

      <span class="c1"># Obtains particles used for training</span>
      <span class="n">idx_type_SF</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__types</span><span class="o">==</span><span class="n">type_</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
      <span class="n">particles_R</span> <span class="o">=</span> <span class="n">skl</span><span class="o">.</span><span class="n">utils</span><span class="o">.</span><span class="n">shuffle</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">training_R</span><span class="p">[</span><span class="n">idx_type</span><span class="p">])</span>
      <span class="n">particles_NR</span> <span class="o">=</span> <span class="n">skl</span><span class="o">.</span><span class="n">utils</span><span class="o">.</span><span class="n">shuffle</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">training_NR</span><span class="p">[</span><span class="n">idx_type</span><span class="p">])</span>
      <span class="k">if</span> <span class="n">n_eg</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
        <span class="n">n_eg_type</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">particles_R</span><span class="p">),</span> <span class="nb">len</span><span class="p">(</span><span class="n">particles_NR</span><span class="p">))</span>
      <span class="k">else</span><span class="p">:</span>
        <span class="n">n_eg_type</span> <span class="o">=</span> <span class="n">n_eg</span><span class="p">[</span><span class="n">idx_type</span><span class="p">]</span>
      <span class="n">particles_R</span> <span class="o">=</span> <span class="n">particles_R</span><span class="p">[:</span><span class="n">n_eg_type</span><span class="p">]</span>
      <span class="n">particles_NR</span> <span class="o">=</span> <span class="n">particles_NR</span><span class="p">[:</span><span class="n">n_eg_type</span><span class="p">]</span>
      <span class="n">training_particles</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">([</span><span class="n">particles_R</span><span class="p">,</span> <span class="n">particles_NR</span><span class="p">])</span>

      <span class="c1"># Obtains structure functions (X) and targets (Y) for training</span>
      <span class="n">mean_SF_type</span> <span class="o">=</span> <span class="n">mean_SF</span><span class="p">[</span><span class="n">idx_type_SF</span><span class="p">]</span>
      <span class="n">std_SF_type</span> <span class="o">=</span> <span class="n">std_SF</span><span class="p">[</span><span class="n">idx_type_SF</span><span class="p">]</span>
      <span class="n">X_full</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ParticlesToSFs</span><span class="p">(</span><span class="n">training_particles</span><span class="p">)</span>
      <span class="n">X_type</span> <span class="o">=</span> <span class="p">(</span><span class="n">X_full</span><span class="p">[:,</span><span class="n">idx_type_SF</span><span class="p">]</span><span class="o">-</span><span class="n">mean_SF_type</span><span class="p">)</span><span class="o">/</span><span class="n">std_SF_type</span>
      <span class="n">Y</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">((</span><span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="n">n_eg_type</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_eg_type</span><span class="p">)))</span>

      <span class="c1"># Trains plane and stores results</span>
      <span class="n">grid_search</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">X_type</span><span class="p">,</span> <span class="n">Y</span><span class="p">)</span>
      <span class="n">plane</span> <span class="o">=</span> <span class="n">grid_search</span><span class="o">.</span><span class="n">best_estimator_</span><span class="o">.</span><span class="n">coef_</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
      <span class="n">intercept</span> <span class="o">=</span> <span class="n">grid_search</span><span class="o">.</span><span class="n">best_estimator_</span><span class="o">.</span><span class="n">intercept_</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

      <span class="c1"># Converts from normalized SFs to un-normalized</span>
      <span class="n">plane</span> <span class="o">=</span> <span class="n">plane</span> <span class="o">/</span> <span class="n">std_SF_type</span>
      <span class="n">intercept</span> <span class="o">=</span> <span class="n">intercept</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">plane</span><span class="p">,</span><span class="n">mean_SF_type</span><span class="p">)</span>

      <span class="c1"># Normalizes plane so that sofness has an std of 1</span>
      <span class="k">if</span> <span class="n">norm_plane</span><span class="p">:</span>
        <span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">plane</span><span class="p">,</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cov_SF</span><span class="p">,</span><span class="n">plane</span><span class="p">))</span>
        <span class="n">plane</span> <span class="o">/=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
        <span class="n">intercept</span> <span class="o">/=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>

      <span class="c1"># Stores results</span>
      <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__containsRadial</span><span class="p">:</span>
        <span class="n">idx_type_SF_rad</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">radial_Xs</span><span class="o">==</span><span class="n">type_</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">radial_plane</span><span class="p">[</span><span class="n">idx_type</span><span class="p">,</span> <span class="n">idx_type_SF_rad</span><span class="p">]</span> <span class="o">=</span> \
              <span class="n">plane</span><span class="p">[:</span><span class="bp">self</span><span class="o">.</span><span class="n">__n_SF_rad</span><span class="p">]</span>
      <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__containsAngular</span><span class="p">:</span>
        <span class="n">idx_type_SF_ang</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">angular_Xs</span><span class="o">==</span><span class="n">type_</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">angular_plane</span><span class="p">[</span><span class="n">idx_type</span><span class="p">,</span> <span class="n">idx_type_SF_ang</span><span class="p">]</span> <span class="o">=</span> \
              <span class="n">plane</span><span class="p">[</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">__n_SF_ang</span><span class="p">:]</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">intercept</span><span class="p">[</span><span class="n">idx_type</span><span class="p">]</span> <span class="o">=</span> <span class="n">intercept</span>

    <span class="c1"># Marks program as run</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__train</span> <span class="o">=</span> <span class="kc">True</span>

    <span class="c1"># Allows for chained statements</span>
    <span class="k">return</span> <span class="bp">self</span></div>

  <span class="k">def</span> <span class="nf">__InitializeNorms</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">norm_SF</span><span class="p">,</span> <span class="n">norm_plane</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Initializes normalization or structure functions or planes</span>

<span class="sd">    Initializes the parameters __mean_SF, __std_SF, and __covList.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    norm_SF : boolean, optional</span>
<span class="sd">      Whether to normalize structure functions before running linear</span>
<span class="sd">      SVM. This typically leads to better fits. If true, we subtract</span>
<span class="sd">      the mean and divide by the STDev of all structure functions. If</span>
<span class="sd">      not set, default is True.</span>
<span class="sd">    norm_plane : boolean, optional</span>
<span class="sd">      Ensures the standard deviation of softness is 1. If not set,</span>
<span class="sd">      default is true.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># Initializes values    </span>
    <span class="n">nc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span>
    <span class="n">n_SF</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__n_SF_rad</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">__n_SF_ang</span>
    <span class="n">mean_SF</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_SF</span><span class="p">)</span>
    <span class="n">std_SF</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_SF</span><span class="p">)</span>
    <span class="n">cov_SF</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">n_SF</span><span class="p">,</span><span class="n">n_SF</span><span class="p">))</span>
    <span class="n">n_parts</span> <span class="o">=</span> <span class="mi">0</span>

    <span class="k">for</span> <span class="n">idx_type</span><span class="p">,</span> <span class="n">type_</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__types_unique</span><span class="p">):</span>
      <span class="n">idx_type_SF</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__types</span><span class="o">==</span><span class="n">type_</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
      <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_n_f</span><span class="p">):</span>
        <span class="c1"># Finds particle typtes for each particle. </span>
        <span class="n">particle_types</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__NcIO_dyn</span><span class="o">.</span><span class="n">GetDataCol</span><span class="p">(</span><span class="n">f</span><span class="p">,</span><span class="s1">&#39;type&#39;</span><span class="p">)</span>
        <span class="n">type_ids</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">particle_types</span><span class="o">==</span><span class="n">type_</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>

        <span class="c1"># Obtains radial and angular SFs for f</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__containsRadial</span><span class="p">:</span>
          <span class="n">rSF</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;radial_structures&#39;</span><span class="p">][</span><span class="n">f</span><span class="p">][</span><span class="n">type_ids</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
          <span class="n">rSF</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="nb">len</span><span class="p">(</span><span class="n">type_ids</span><span class="p">),</span><span class="mi">0</span><span class="p">))</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__containsAngular</span><span class="p">:</span>
          <span class="n">aSF</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;angular_structures&#39;</span><span class="p">][</span><span class="n">f</span><span class="p">][</span><span class="n">type_ids</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
          <span class="n">aSF</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="nb">len</span><span class="p">(</span><span class="n">type_ids</span><span class="p">),</span><span class="mi">0</span><span class="p">))</span>
        <span class="n">SF</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">hstack</span><span class="p">((</span><span class="n">rSF</span><span class="p">,</span><span class="n">aSF</span><span class="p">))</span>

        <span class="c1"># Counts number of SFs in frame and sums particles to find</span>
        <span class="c1"># mean. We do not use nanmean function in case number of </span>
        <span class="c1"># particles changes between frames</span>
        <span class="n">n_parts</span> <span class="o">+=</span> <span class="n">np</span><span class="o">.</span><span class="n">count_nonzero</span><span class="p">(</span><span class="o">~</span><span class="n">np</span><span class="o">.</span><span class="n">isnan</span><span class="p">(</span><span class="n">SF</span><span class="p">[:,</span><span class="mi">0</span><span class="p">]))</span>
        <span class="n">mean_SF</span> <span class="o">+=</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">(</span><span class="n">SF</span><span class="p">,</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
        <span class="n">cov_SF</span><span class="p">[</span><span class="n">idx_type_SF</span><span class="p">[:,</span><span class="kc">None</span><span class="p">],</span><span class="n">idx_type_SF</span><span class="p">[</span><span class="kc">None</span><span class="p">,:]]</span> <span class="o">+=</span> \
              <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">SF</span><span class="o">.</span><span class="n">T</span><span class="p">,</span><span class="n">SF</span><span class="p">)</span>
      
      <span class="c1"># Calculates mean and covariance</span>
      <span class="n">mean_SF</span><span class="p">[</span><span class="n">idx_type_SF</span><span class="p">]</span> <span class="o">/=</span> <span class="nb">float</span><span class="p">(</span><span class="n">n_parts</span><span class="p">)</span>
      <span class="n">cov_SF</span><span class="p">[</span><span class="n">idx_type_SF</span><span class="p">[:,</span><span class="kc">None</span><span class="p">],</span><span class="n">idx_type_SF</span><span class="p">[</span><span class="kc">None</span><span class="p">,:]]</span> <span class="o">/=</span> \
            <span class="nb">float</span><span class="p">(</span><span class="n">n_parts</span><span class="p">)</span>
      <span class="n">cov_SF</span><span class="p">[</span><span class="n">idx_type_SF</span><span class="p">[:,</span><span class="kc">None</span><span class="p">],</span><span class="n">idx_type_SF</span><span class="p">[</span><span class="kc">None</span><span class="p">,:]]</span> <span class="o">-=</span> \
            <span class="n">np</span><span class="o">.</span><span class="n">outer</span><span class="p">(</span><span class="n">mean_SF</span><span class="p">[</span><span class="n">idx_type_SF</span><span class="p">],</span><span class="n">mean_SF</span><span class="p">[</span><span class="n">idx_type_SF</span><span class="p">])</span>
      <span class="n">std_SF</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">diagonal</span><span class="p">(</span><span class="n">cov_SF</span><span class="p">))</span>

      <span class="bp">self</span><span class="o">.</span><span class="n">_mean_SF</span> <span class="o">=</span> <span class="n">mean_SF</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_cov_SF</span> <span class="o">=</span> <span class="n">cov_SF</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_std_SF</span> <span class="o">=</span> <span class="n">std_SF</span>

  <span class="k">def</span> <span class="nf">_ParticlesToSFs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">particles</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Converts particle frames and ids to structure functions</span>

<span class="sd">    Obtains structure functions of all particles in the particles</span>
<span class="sd">    array.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    particles : numpy int array (n_particles, 2)</span>
<span class="sd">      An array containing the frames and particle ids of particles to</span>
<span class="sd">      obtain structure functions. First column is for frame and second</span>
<span class="sd">      is for particle id.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">particles</span> <span class="o">=</span> <span class="n">particles</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">int</span><span class="p">)</span>
    <span class="n">nc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span>
    <span class="n">n_particles</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">particles</span><span class="p">)</span>
    <span class="n">n_SF</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__n_SF_rad</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">__n_SF_ang</span>
    <span class="n">SFs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="n">n_particles</span><span class="p">,</span> <span class="n">n_SF</span><span class="p">))</span>
    <span class="k">for</span> <span class="n">idx</span><span class="p">,</span> <span class="n">particle</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">particles</span><span class="p">):</span>
      <span class="n">f</span> <span class="o">=</span> <span class="n">particle</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
      <span class="n">p</span> <span class="o">=</span> <span class="n">particle</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
      <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__containsRadial</span><span class="p">:</span>
        <span class="n">rSF</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;radial_structures&#39;</span><span class="p">][</span><span class="n">f</span><span class="p">][</span><span class="n">p</span><span class="p">]</span>
      <span class="k">else</span><span class="p">:</span>
        <span class="n">rSF</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__n_SF_rad</span><span class="p">)</span>
      <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__containsAngular</span><span class="p">:</span>
        <span class="n">aSF</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;angular_structures&#39;</span><span class="p">][</span><span class="n">f</span><span class="p">][</span><span class="n">p</span><span class="p">]</span>
      <span class="k">else</span><span class="p">:</span>
        <span class="n">aSF</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__n_SF_ang</span><span class="p">)</span>
      <span class="n">SFs</span><span class="p">[</span><span class="n">idx</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">((</span><span class="n">rSF</span><span class="p">,</span><span class="n">aSF</span><span class="p">))</span>
    <span class="k">return</span> <span class="n">SFs</span>

<div class="viewcode-block" id="RSoft.SelectTrainingSet"><a class="viewcode-back" href="../RSoftTools.html#RSoftTools.RSoft.SelectTrainingSet">[docs]</a>  <span class="k">def</span> <span class="nf">SelectTrainingSet</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">rearrangement_cutoff</span><span class="p">,</span> \
        <span class="n">non_rearrangement_frames</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> \
        <span class="n">non_rearrangement_cutoff</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">str_mask</span> <span class="o">=</span> <span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Selects training set</span>

<span class="sd">    Selects the training set from the dynamic AMBER file. </span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    rearrangement_cutoff : numpy array (n_types)</span>
<span class="sd">      Numpy array with a rearrangement cutoff for the dynamical </span>
<span class="sd">      quantity in data column of AMBER dynamical file.</span>
<span class="sd">    non_rearrangement_frames : numpy int array (n_types), optional</span>
<span class="sd">      Numpy array of frames for a particle not to rearrange before </span>
<span class="sd">      being counted as part of non-rearranging training set for each </span>
<span class="sd">      particle type. If not set, assumes 0 frames for each particle </span>
<span class="sd">      type, i.e. instantaneously less than non_rearrangement_cutoff.</span>
<span class="sd">    non_rearrangement_cutoff : numpy array (n_types), optional</span>
<span class="sd">      Numpy array with a non-rearrangement cutoff for the dynamical</span>
<span class="sd">      quantity in data column of AMBER dynamical file. If not set,</span>
<span class="sd">      uses the rearrangement_cutoff.</span>
<span class="sd">    str_mask : str, optional</span>
<span class="sd">      Name of the data column of AMBER dynamic file corresponding to </span>
<span class="sd">      a mask of 0&#39;s and 1&#39;s in which 1&#39;s are particles that may be</span>
<span class="sd">      included in training set and 0&#39;s cannot.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># Initializes parameters</span>
    <span class="n">dynamics_name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__dynamics_name</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">training_R</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">training_NR</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="c1"># If non_rearrangement_cutoff not set, chooses it to be </span>
    <span class="c1"># rearrangement_cutoff</span>
    <span class="k">if</span> <span class="n">non_rearrangement_cutoff</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
      <span class="n">non_rearrangement_cutoff</span> <span class="o">=</span> <span class="n">rearrangement_cutoff</span>
    <span class="k">if</span> <span class="n">non_rearrangement_frames</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
      <span class="n">non_rearrangement_frames</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__n_type</span><span class="p">)</span>

    <span class="c1"># for each type finds rearranging and non-rearranging cutoffs</span>
    <span class="k">for</span> <span class="n">idx_type</span><span class="p">,</span> <span class="n">type_</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__types_unique</span><span class="p">):</span>
      <span class="n">r_cut</span> <span class="o">=</span> <span class="n">rearrangement_cutoff</span><span class="p">[</span><span class="n">idx_type</span><span class="p">]</span>
      <span class="n">nr_cut</span> <span class="o">=</span> <span class="n">non_rearrangement_cutoff</span><span class="p">[</span><span class="n">idx_type</span><span class="p">]</span>
      <span class="n">n_nr_f</span> <span class="o">=</span> <span class="n">non_rearrangement_frames</span><span class="p">[</span><span class="n">idx_type</span><span class="p">]</span>
      <span class="n">rs_arr_all</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">0</span><span class="p">,</span><span class="mi">2</span><span class="p">))</span>
      <span class="n">nrs_arr_all</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="mi">0</span><span class="p">,</span><span class="mi">2</span><span class="p">))</span>
      <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_n_f</span><span class="p">):</span>
        <span class="c1"># obtains mask for all particles at frame f</span>
        <span class="k">if</span> <span class="n">str_mask</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
          <span class="n">mask</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_n_p</span><span class="p">)</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">bool</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
          <span class="n">mask</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__NcIO_dyn</span><span class="o">.</span><span class="n">GetDataCol</span><span class="p">(</span><span class="n">f</span><span class="p">,</span><span class="n">str_mask</span><span class="p">)</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">bool</span><span class="p">)</span>

        <span class="c1"># creates types mask</span>
        <span class="n">particle_types</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__NcIO_dyn</span><span class="o">.</span><span class="n">GetDataCol</span><span class="p">(</span><span class="n">f</span><span class="p">,</span><span class="s1">&#39;type&#39;</span><span class="p">)</span>
        <span class="n">type_mask</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">particle_types</span><span class="o">==</span><span class="n">type_</span><span class="p">,</span> <span class="kc">True</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>

        <span class="c1"># Finds rearranging particles at frame f</span>
        <span class="n">dynamics_f</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__NcIO_dyn</span><span class="o">.</span><span class="n">GetDataCol</span><span class="p">(</span><span class="n">f</span><span class="p">,</span><span class="n">dynamics_name</span><span class="p">)</span>
        <span class="n">r_mask</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">dynamics_f</span> <span class="o">&gt;</span> <span class="n">r_cut</span><span class="p">,</span> <span class="kc">True</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
        <span class="n">rs_arr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">mask</span><span class="o">*</span><span class="n">type_mask</span><span class="o">*</span><span class="n">r_mask</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">f_arr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">rs_arr</span><span class="p">))</span><span class="o">*</span><span class="n">f</span>
        <span class="n">rs_arr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">((</span><span class="n">f_arr</span><span class="p">,</span> <span class="n">rs_arr</span><span class="p">))</span><span class="o">.</span><span class="n">T</span>
        <span class="n">rs_arr_all</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">((</span><span class="n">rs_arr_all</span><span class="p">,</span> <span class="n">rs_arr</span><span class="p">))</span>

        <span class="c1"># Finds non-rearranging particles at frame f-n_nr_f/2</span>
        <span class="k">if</span> <span class="n">f</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
          <span class="n">dynamics_arr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">dynamics_f</span><span class="p">])</span>
        <span class="k">else</span><span class="p">:</span>
          <span class="n">dynamics_arr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">((</span><span class="n">dynamics_arr</span><span class="p">,</span> \
                  <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">dynamics_f</span><span class="p">])))</span>
        <span class="k">if</span> <span class="n">f</span> <span class="o">&gt;</span> <span class="n">n_nr_f</span><span class="p">:</span>
          <span class="n">dynamics_arr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="n">dynamics_arr</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">f</span> <span class="o">&gt;=</span> <span class="n">n_nr_f</span><span class="p">:</span>
          <span class="c1"># Finds particles that have been below the non-rearranging</span>
          <span class="c1"># cutoff for previous n_nr_f frames.</span>
          <span class="n">nr_mask</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">all</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">dynamics_arr</span><span class="o">&lt;</span><span class="n">nr_cut</span><span class="p">,</span> <span class="kc">True</span><span class="p">,</span> <span class="kc">False</span><span class="p">),</span>\
                <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
          <span class="n">nrs_arr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">mask</span><span class="o">*</span><span class="n">type_mask</span><span class="o">*</span><span class="n">nr_mask</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
          <span class="n">f_arr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">nrs_arr</span><span class="p">))</span><span class="o">*</span><span class="p">(</span><span class="n">f</span><span class="o">-</span><span class="nb">int</span><span class="p">(</span><span class="n">n_nr_f</span><span class="o">/</span><span class="mi">2</span><span class="p">))</span>
          <span class="n">nrs_arr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">((</span><span class="n">f_arr</span><span class="p">,</span> <span class="n">nrs_arr</span><span class="p">))</span><span class="o">.</span><span class="n">T</span>
          <span class="n">nrs_arr_all</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">((</span><span class="n">nrs_arr_all</span><span class="p">,</span> <span class="n">nrs_arr</span><span class="p">))</span>
      
      <span class="c1"># Saves all rearranging and non-rearranging examples for frame</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">training_R</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">rs_arr_all</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">int</span><span class="p">))</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">training_NR</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">nrs_arr_all</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">int</span><span class="p">))</span>
      
    <span class="bp">self</span><span class="o">.</span><span class="n">__selectTrainingSet</span> <span class="o">=</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="RSoft.WritePlane"><a class="viewcode-back" href="../RSoftTools.html#RSoftTools.RSoft.WritePlane">[docs]</a>  <span class="k">def</span> <span class="nf">WritePlane</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Writes plane to RSoftPlane file</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__train</span><span class="p">:</span>
      <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: Must use Train before WritePlane&#39;</span><span class="p">)</span>
      <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__openPlaneO</span><span class="p">:</span>
      <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: Must use OpenPlaneO before WritePlane&#39;</span><span class="p">)</span>
      <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>

    <span class="c1"># Defines angular dimensions</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s1">&#39;type&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">__n_type</span><span class="p">)</span>

    <span class="c1"># Defines variables</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__containsRadial</span><span class="p">:</span>
      <span class="n">rad_plane_id</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span>\
            <span class="s1">&#39;radial_plane&#39;</span><span class="p">,</span> <span class="s1">&#39;f4&#39;</span><span class="p">,</span> \
            <span class="p">(</span><span class="s1">&#39;type&#39;</span><span class="p">,</span><span class="s1">&#39;radial_structure_functions&#39;</span><span class="p">))</span>
      <span class="n">rad_plane_id</span><span class="p">[:]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">radial_plane</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__containsAngular</span><span class="p">:</span>
      <span class="n">ang_plane_id</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span>\
            <span class="s1">&#39;angular_plane&#39;</span><span class="p">,</span> <span class="s1">&#39;f4&#39;</span><span class="p">,</span> \
            <span class="p">(</span><span class="s1">&#39;type&#39;</span><span class="p">,</span><span class="s1">&#39;angular_structure_functions&#39;</span><span class="p">))</span>
      <span class="n">ang_plane_id</span><span class="p">[:]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">angular_plane</span>
    <span class="n">intercept_id_O</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span>\
          <span class="s1">&#39;intercept&#39;</span><span class="p">,</span> <span class="s1">&#39;f4&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;type&#39;</span><span class="p">))</span>
    <span class="n">intercept_id_O</span><span class="p">[:]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">intercept</span></div>

<div class="viewcode-block" id="RSoft.GetRadial"><a class="viewcode-back" href="../RSoftTools.html#RSoftTools.RSoft.GetRadial">[docs]</a>  <span class="k">def</span> <span class="nf">GetRadial</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">f</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Gets radial structure functions </span>

<span class="sd">    Gets radial structure functions for frame f.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    f : int</span>
<span class="sd">      Frame number to obtain radial structure functions</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__openSFI</span><span class="p">:</span>
      <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: Must use OpenSFI before GetRadial&#39;</span><span class="p">)</span>
      <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__containsRadial</span><span class="p">:</span>
      <span class="n">SF</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;radial_structures&#39;</span><span class="p">][</span><span class="n">f</span><span class="p">][:]</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: RSoftSF input file does not contain radial&#39;</span><span class="p">)</span>
      <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;      structures&#39;</span><span class="p">)</span>
      <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>

    <span class="c1"># Marks as run</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__getRadial</span> <span class="o">=</span> <span class="kc">True</span>

    <span class="k">return</span> <span class="n">SF</span></div>

<div class="viewcode-block" id="RSoft.GetAngular"><a class="viewcode-back" href="../RSoftTools.html#RSoftTools.RSoft.GetAngular">[docs]</a>  <span class="k">def</span> <span class="nf">GetAngular</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">f</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Gets angular structure functions </span>

<span class="sd">    Gets angular structure functions for frame f.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    f : int</span>
<span class="sd">      Frame number to obtain angular structure functions</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__openSFI</span><span class="p">:</span>
      <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: Must use OpenSFI before GetAngular&#39;</span><span class="p">)</span>
      <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__containsAngular</span><span class="p">:</span>
      <span class="n">SF</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;angular_structures&#39;</span><span class="p">][</span><span class="n">f</span><span class="p">][:]</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: RSoftSF input file does not contain angular&#39;</span><span class="p">)</span>
      <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;      structures&#39;</span><span class="p">)</span>
      <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>

    <span class="c1"># Marks as run</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__getAngular</span> <span class="o">=</span> <span class="kc">True</span>

    <span class="k">return</span> <span class="n">SF</span></div>

<div class="viewcode-block" id="RSoft.SetRadial"><a class="viewcode-back" href="../RSoftTools.html#RSoftTools.RSoft.SetRadial">[docs]</a>  <span class="k">def</span> <span class="nf">SetRadial</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="n">SF</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Sets radial structure functions </span>

<span class="sd">    Sets radial structure functions for frame f.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    f : int</span>
<span class="sd">      Frame number to set radial structure functions</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__openSFO</span><span class="p">:</span>
      <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: Must use OpenSFO before SetRadial&#39;</span><span class="p">)</span>
      <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>

    <span class="c1"># Creates dimensions and variables to hold structures</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__setRadial</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__setAngular</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s1">&#39;frame&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s1">&#39;atom&#39;</span><span class="p">,</span> <span class="n">SF</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__setRadial</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s1">&#39;radial_structure_functions&#39;</span><span class="p">,</span>\
            <span class="n">SF</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O_radial_structures</span> <span class="o">=</span> \
            <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;radial_structures&#39;</span><span class="p">,</span> \
            <span class="s1">&#39;f4&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;frame&#39;</span><span class="p">,</span><span class="s1">&#39;atom&#39;</span><span class="p">,</span><span class="s1">&#39;radial_structure_functions&#39;</span><span class="p">))</span>

    <span class="c1"># Stores SFs</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O_radial_structures</span><span class="p">[</span><span class="n">f</span><span class="p">]</span> <span class="o">=</span> <span class="n">SF</span>

    <span class="c1"># Marks as run</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__setRadial</span> <span class="o">=</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="RSoft.SetAngular"><a class="viewcode-back" href="../RSoftTools.html#RSoftTools.RSoft.SetAngular">[docs]</a>  <span class="k">def</span> <span class="nf">SetAngular</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="n">SF</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Sets angular structure functions </span>

<span class="sd">    Sets angular structure functions for frame f.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    f : int</span>
<span class="sd">      Frame number to set angular structure functions</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__openSFO</span><span class="p">:</span>
      <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: Must use OpenSFO before SetAngular&#39;</span><span class="p">)</span>
      <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>

    <span class="c1"># Creates dimensions and variables to hold structures</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__setRadial</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__setAngular</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s1">&#39;frame&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s1">&#39;atom&#39;</span><span class="p">,</span> <span class="n">SF</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__setAngular</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s1">&#39;radial_structure_functions&#39;</span><span class="p">,</span>\
            <span class="n">SF</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O_angular_structures</span> <span class="o">=</span> \
            <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;angular_structures&#39;</span><span class="p">,</span> \
            <span class="s1">&#39;f4&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;frame&#39;</span><span class="p">,</span><span class="s1">&#39;atom&#39;</span><span class="p">,</span><span class="s1">&#39;angular_structure_functions&#39;</span><span class="p">))</span>

    <span class="c1"># Stores SFs</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O_angular_structures</span><span class="p">[</span><span class="n">f</span><span class="p">]</span> <span class="o">=</span> <span class="n">SF</span>

    <span class="c1"># Marks as run</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__setAngular</span> <span class="o">=</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="RSoft.CloseSFI"><a class="viewcode-back" href="../RSoftTools.html#RSoftTools.RSoft.CloseSFI">[docs]</a>  <span class="k">def</span> <span class="nf">CloseSFI</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Closes input of RSoftSF file</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_I</span><span class="o">.</span><span class="n">close</span><span class="p">()</span></div>

<div class="viewcode-block" id="RSoft.CloseSFO"><a class="viewcode-back" href="../RSoftTools.html#RSoftTools.RSoft.CloseSFO">[docs]</a>  <span class="k">def</span> <span class="nf">CloseSFO</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Closes output of RSoftSF</span>
<span class="sd">    &quot;&quot;&quot;</span></div>

<div class="viewcode-block" id="RSoft.CloseDynamicsI"><a class="viewcode-back" href="../RSoftTools.html#RSoftTools.RSoft.CloseDynamicsI">[docs]</a>  <span class="k">def</span> <span class="nf">CloseDynamicsI</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>  
    <span class="sd">&quot;&quot;&quot; CLoses input of AMBER NetCDF dynamics file</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__NcIO_dyn</span><span class="o">.</span><span class="n">CloseI</span><span class="p">()</span></div>

<div class="viewcode-block" id="RSoft.ClosePlaneO"><a class="viewcode-back" href="../RSoftTools.html#RSoftTools.RSoft.ClosePlaneO">[docs]</a>  <span class="k">def</span> <span class="nf">ClosePlaneO</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Closes output of RSoftPlane file</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__nc_RSoft_O</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> </div></div>



<div class="viewcode-block" id="MDTools"><a class="viewcode-back" href="../RSoftTools.html#RSoftTools.MDTools">[docs]</a><span class="k">class</span> <span class="nc">MDTools</span><span class="p">:</span>
  <span class="sd">&quot;&quot;&quot; Molecular Dynamics Tools for python</span>

<span class="sd">  This class is designed to provide some standard molecular dynamics</span>
<span class="sd">  tools to analyze trajectories.</span>

<span class="sd">  &quot;&quot;&quot;</span>

  <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">tmp</span> <span class="o">=</span> <span class="kc">False</span>

<div class="viewcode-block" id="MDTools.DeltaR"><a class="viewcode-back" href="../RSoftTools.html#RSoftTools.MDTools.DeltaR">[docs]</a>  <span class="k">def</span> <span class="nf">DeltaR</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">rf</span><span class="p">,</span> <span class="n">ri</span><span class="p">,</span> <span class="n">bb</span><span class="p">,</span> <span class="n">bc</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Difference between two vectors or sets of vectors</span>
<span class="sd">    </span>
<span class="sd">    Calculates the difference between two positions rf and ri (rf-ri) </span>
<span class="sd">    with respect to the box boundaries (bb) and the boundary conditions</span>
<span class="sd">    (bc). The numpy arrays rf and ri can either be single particle</span>
<span class="sd">    positions or sets of particle positions. Let d = dimension of the</span>
<span class="sd">    space and N = number of vectors.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    rf : numpy array, either (d) or (N, d)</span>
<span class="sd">      Final positions of particle(s) in d-dimensional space.</span>
<span class="sd">    ri : numpy array, either (d) or (N, d)</span>
<span class="sd">      Initial positions of particle(s) in d-dimensional space.</span>
<span class="sd">    bb : numpy array, (d, 2)</span>
<span class="sd">      Box boundaries of simulation or the experiment. For d=2, this</span>
<span class="sd">      should be formatted [[low_x, high_x],[low_y, high_y]]. In d=3,</span>
<span class="sd">      [[low_x, high_x],[low_y, high_y],[low_z, high_z]].</span>
<span class="sd">    bc : numpy str array, (d)</span>
<span class="sd">      Boundary conditions of the experiment or simulation. Each value</span>
<span class="sd">      must be a single character string denoting the boundary condition</span>
<span class="sd">      in each direction. &#39;p&#39; means periodic boundary conditions. &#39;s&#39; </span>
<span class="sd">      means shrink wrapped bounday conditions. &#39;f&#39; means fixed boundary</span>
<span class="sd">      conditions.</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    dr : numpy array, either (d) or (N, d)</span>
<span class="sd">      The rf-ri given the box boundaries and boundary conditions.</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="c1"># Checks if all dimensions are matching</span>
    <span class="n">dim_f</span> <span class="o">=</span> <span class="n">rf</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
    <span class="n">dim_i</span> <span class="o">=</span> <span class="n">ri</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
    <span class="n">dim_bc</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">bc</span><span class="p">)</span>
    <span class="n">dim_bb</span> <span class="o">=</span> <span class="n">bb</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
    <span class="k">if</span> <span class="n">dim_f</span> <span class="o">!=</span> <span class="n">dim_i</span> <span class="ow">or</span> <span class="n">dim_f</span> <span class="o">!=</span> <span class="n">dim_bc</span> <span class="ow">or</span> <span class="n">dim_f</span> <span class="o">!=</span> <span class="n">dim_bb</span><span class="p">:</span>
      <span class="n">str_</span> <span class="o">=</span> <span class="s1">&#39;ERROR: dimension mismatch for rf, ri, bc, and&#39;</span>
      <span class="n">str_</span> <span class="o">+=</span> <span class="s1">&#39; bb.shape[0]&#39;</span>
      <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="n">str_</span><span class="p">)</span>

    <span class="c1"># Checks if rf and ri are vectors or vector of vectors</span>
    <span class="n">arr_f_dim</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">rf</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span>
    <span class="n">arr_i_dim</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">ri</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span>

    <span class="c1"># CASE: both rf and ri are vectors</span>
    <span class="k">if</span> <span class="n">arr_f_dim</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">arr_i_dim</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
      <span class="n">dr</span> <span class="o">=</span> <span class="n">rf</span> <span class="o">-</span> <span class="n">ri</span>
      <span class="n">idx_p_arr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">bc</span><span class="o">==</span><span class="s1">&#39;p&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
      <span class="k">for</span> <span class="n">idx_p</span> <span class="ow">in</span> <span class="n">idx_p_arr</span><span class="p">:</span>
        <span class="n">L</span> <span class="o">=</span> <span class="n">bb</span><span class="p">[</span><span class="n">idx_p</span><span class="p">,</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">bb</span><span class="p">[</span><span class="n">idx_p</span><span class="p">,</span><span class="mi">0</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">dr</span><span class="p">[</span><span class="n">idx_p</span><span class="p">]</span><span class="o">&gt;</span><span class="n">L</span><span class="o">/</span><span class="mi">2</span><span class="p">:</span> <span class="n">dr</span><span class="p">[</span><span class="n">idx_p</span><span class="p">]</span> <span class="o">-=</span> <span class="n">L</span>
        <span class="k">if</span> <span class="n">dr</span><span class="p">[</span><span class="n">idx_p</span><span class="p">]</span><span class="o">&lt;-</span><span class="n">L</span><span class="o">/</span><span class="mi">2</span><span class="p">:</span> <span class="n">dr</span><span class="p">[</span><span class="n">idx_p</span><span class="p">]</span> <span class="o">+=</span> <span class="n">L</span>

    <span class="c1"># CASE: rf or ri are vectors of vectors</span>
    <span class="k">elif</span> <span class="n">arr_f_dim</span> <span class="o">==</span> <span class="mi">2</span> <span class="ow">and</span> <span class="n">arr_i_dim</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">or</span>\
          <span class="n">arr_f_dim</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">arr_i_dim</span> <span class="o">==</span> <span class="mi">2</span> <span class="ow">or</span>\
          <span class="n">arr_f_dim</span> <span class="o">==</span> <span class="mi">2</span> <span class="ow">and</span> <span class="n">arr_i_dim</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>

      <span class="c1"># If rf and ri are vectors of vectors ensures they have</span>
      <span class="c1"># the same number of particles, N</span>
      <span class="k">if</span> <span class="n">arr_f_dim</span> <span class="o">==</span> <span class="mi">2</span> <span class="ow">and</span> <span class="n">arr_i_dim</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">rf</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">!=</span> <span class="n">ri</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span>
          <span class="n">str_</span> <span class="o">=</span> <span class="s1">&#39;ERROR: rf and ri don</span><span class="se">\&#39;</span><span class="s1">t have same number of &#39;</span>
          <span class="n">str_</span> <span class="o">+=</span> <span class="s1">&#39;particles, N&#39;</span>
          <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="n">str_</span><span class="p">)</span>

      <span class="n">dr</span> <span class="o">=</span> <span class="n">rf</span> <span class="o">-</span> <span class="n">ri</span>
      <span class="n">idx_p_arr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">bc</span><span class="o">==</span><span class="s1">&#39;p&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
      <span class="k">for</span> <span class="n">idx_p</span> <span class="ow">in</span> <span class="n">idx_p_arr</span><span class="p">:</span>
        <span class="n">L</span> <span class="o">=</span> <span class="n">bb</span><span class="p">[</span><span class="n">idx_p</span><span class="p">,</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">bb</span><span class="p">[</span><span class="n">idx_p</span><span class="p">,</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">dr2</span> <span class="o">=</span> <span class="n">dr</span>
        <span class="n">dr</span><span class="p">[</span><span class="n">dr</span><span class="p">[:,</span><span class="n">idx_p</span><span class="p">]</span><span class="o">&gt;</span><span class="n">L</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span><span class="n">idx_p</span><span class="p">]</span> <span class="o">-=</span> <span class="n">L</span>
        <span class="n">dr</span><span class="p">[</span><span class="n">dr</span><span class="p">[:,</span><span class="n">idx_p</span><span class="p">]</span><span class="o">&lt;-</span><span class="n">L</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span><span class="n">idx_p</span><span class="p">]</span> <span class="o">+=</span> <span class="n">L</span>

    <span class="c1"># CASE: rf or ri are neither vectors or vectors of vectors</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="s1">&#39;ERROR: rf or ri are not vectors or vectors of vectors&#39;</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">dr</span></div>
            
<div class="viewcode-block" id="MDTools.GetNList"><a class="viewcode-back" href="../RSoftTools.html#RSoftTools.MDTools.GetNList">[docs]</a>  <span class="k">def</span> <span class="nf">GetNList</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pos_t</span><span class="p">,</span> <span class="n">bb_t</span><span class="p">,</span> <span class="n">bc</span><span class="p">,</span> <span class="n">R_c</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Obtains a neighbor list for a set of particles</span>

<span class="sd">    Finds all of the neighbors within a cuttoff distance (R_c) for a </span>
<span class="sd">    set of particles (pos_t) given a set of box boundaries (bb_t), and</span>
<span class="sd">    a set of boundary conditions.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    pos_t : numpy array, (n_p, d)</span>
<span class="sd">      Set of n_p particle positions in d-dimensional space</span>
<span class="sd">    bb_t : numpy array, (d, 2)</span>
<span class="sd">      Box boundaries of simulation or the experiment. For d=2, this</span>
<span class="sd">      should be formatted [[low_x, high_x],[low_y, high_y]]. In d=3,</span>
<span class="sd">      [[low_x, high_x],[low_y, high_y],[low_z, high_z]].</span>
<span class="sd">    bc : numpy str array, (d)</span>
<span class="sd">      Boundary conditions of the experiment or simulation. Each value</span>
<span class="sd">      must be a single character string denoting the boundary condition</span>
<span class="sd">      in each direction. &#39;p&#39; means periodic boundary conditions. &#39;s&#39; </span>
<span class="sd">      means shrink wrapped bounday conditions. &#39;f&#39; means fixed boundary</span>
<span class="sd">      conditions.</span>
<span class="sd">    R_c : float</span>
<span class="sd">      Cutoff radius of the simulation.</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    n_list : python array, (n_p)</span>
<span class="sd">      Python list in which n_list[i] is a numpy array of all neighbors</span>
<span class="sd">      of particle i from pos_t. </span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="c1"># Initializes variables</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__R_c_2</span> <span class="o">=</span> <span class="n">R_c</span><span class="o">*</span><span class="n">R_c</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__n_p</span> <span class="o">=</span> <span class="n">pos_t</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__d</span> <span class="o">=</span> <span class="n">pos_t</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__n_list_t</span> <span class="o">=</span> <span class="p">[[]</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__n_p</span><span class="p">)]</span>
    <span class="n">cell_delta_arr</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__InitializeCellDeltaArr</span><span class="p">()</span>

    <span class="c1"># Bins particles into cells</span>
    <span class="n">particles_in_cell</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__BinParticlesIntoCells</span><span class="p">(</span><span class="n">pos_t</span><span class="p">,</span> <span class="n">bb_t</span><span class="p">,</span> <span class="n">R_c</span><span class="p">)</span>
    <span class="n">n_cells_tot</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">particles_in_cell</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">cell_idx</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">n_cells_tot</span><span class="p">):</span>
      <span class="c1"># Initializes shift</span>
      <span class="n">shift</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__d</span><span class="p">)</span>

      <span class="c1"># Adds neighbors from same cell</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">__AddNeighbors</span><span class="p">(</span><span class="n">pos_t</span><span class="p">,</span> <span class="n">particles_in_cell</span><span class="p">,</span> <span class="n">R_c</span><span class="p">,</span> <span class="n">shift</span><span class="p">,</span>\
            <span class="n">cell_idx</span><span class="p">,</span> <span class="n">cell_idx</span><span class="p">)</span>
      <span class="n">cell_pos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__Unstack</span><span class="p">(</span><span class="n">cell_idx</span><span class="p">)</span>

      <span class="c1"># Adds neighbors from neighboring cells</span>
      <span class="k">for</span> <span class="n">cell_delta</span> <span class="ow">in</span> <span class="n">cell_delta_arr</span><span class="p">:</span>

        <span class="c1"># checks if cells are neighbors</span>
        <span class="n">are_neighbors</span><span class="p">,</span> <span class="n">neigh_cell_pos</span><span class="p">,</span> <span class="n">shift</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__AddCellPos</span><span class="p">(</span>\
                <span class="n">cell_pos</span><span class="p">,</span> <span class="n">cell_delta</span><span class="p">,</span> <span class="n">bb_t</span><span class="p">,</span> <span class="n">bc</span><span class="p">)</span>

        <span class="c1"># if cells are neighbors, adds particles to neighbor list</span>
        <span class="k">if</span> <span class="n">are_neighbors</span><span class="p">:</span>
          <span class="n">neigh_cell_idx</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__Stack</span><span class="p">(</span><span class="n">neigh_cell_pos</span><span class="p">)</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">__AddNeighbors</span><span class="p">(</span><span class="n">pos_t</span><span class="p">,</span> <span class="n">particles_in_cell</span><span class="p">,</span> <span class="n">R_c</span><span class="p">,</span> <span class="n">shift</span><span class="p">,</span>
                <span class="n">cell_idx</span><span class="p">,</span> <span class="n">neigh_cell_idx</span><span class="p">)</span>

    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__n_list_t</span></div>

  <span class="k">def</span> <span class="nf">__InitializeCellDeltaArr</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="c1"># determines list of neighoring cells</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__d</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
      <span class="n">cell_delta_arr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span>\
            <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">]])</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">cell_delta_arr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span>\
            <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">],</span>\
            <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">],</span>\
            <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">],</span>\
            <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span>\
            <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">]])</span>
    <span class="k">return</span> <span class="n">cell_delta_arr</span>

  <span class="k">def</span> <span class="nf">__BinParticlesIntoCells</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pos_t</span><span class="p">,</span> <span class="n">bb_t</span><span class="p">,</span> <span class="n">R_c</span><span class="p">):</span>

    <span class="c1"># Finds number of cells in each dimension and cell lengths</span>
    <span class="n">L</span> <span class="o">=</span> <span class="p">(</span><span class="n">bb_t</span><span class="p">[:,</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="n">bb_t</span><span class="p">[:,</span><span class="mi">0</span><span class="p">])</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">float</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__n_cells</span> <span class="o">=</span> <span class="p">(</span><span class="n">L</span><span class="o">/</span><span class="n">R_c</span><span class="p">)</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">int</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__n_cells</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">__n_cells</span> <span class="o">&lt;</span> <span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="mi">3</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__cell_lengths</span> <span class="o">=</span> <span class="n">L</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">__n_cells</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">__n_cells_tot</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">prod</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__n_cells</span><span class="p">)</span>

    <span class="c1"># Place particles in cells</span>
    <span class="n">particles_in_cell</span> <span class="o">=</span> <span class="p">[[]</span> <span class="k">for</span> <span class="n">cells</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__n_cells_tot</span><span class="p">)]</span>
    <span class="n">cell_pos</span> <span class="o">=</span> <span class="p">((</span><span class="n">pos_t</span><span class="o">-</span><span class="n">bb_t</span><span class="p">[:,</span><span class="mi">0</span><span class="p">])</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">__cell_lengths</span><span class="p">)</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">int</span><span class="p">)</span>
    <span class="n">cell_idx</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__Stack</span><span class="p">(</span><span class="n">cell_pos</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">pp</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">pos_t</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]):</span>
      <span class="n">particles_in_cell</span><span class="p">[</span><span class="n">cell_idx</span><span class="p">[</span><span class="n">pp</span><span class="p">]]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pp</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">particles_in_cell</span>

  <span class="k">def</span> <span class="nf">__Stack</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cell_pos</span><span class="p">):</span>
    <span class="c1"># CASE: cell_pos is a vector</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">cell_pos</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span><span class="o">==</span><span class="mi">1</span><span class="p">:</span>
      <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__d</span><span class="o">==</span><span class="mi">2</span><span class="p">:</span>
        <span class="n">n_x</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__n_cells</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">cell_idx</span> <span class="o">=</span> <span class="n">cell_pos</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="n">cell_pos</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="n">n_x</span>
      <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">__d</span><span class="o">==</span><span class="mi">3</span><span class="p">:</span>
        <span class="n">n_x</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__n_cells</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">n_y</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__n_cells</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
        <span class="n">cell_idx</span> <span class="o">=</span> <span class="n">cell_pos</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="p">(</span><span class="n">cell_pos</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">+</span><span class="n">cell_pos</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">*</span><span class="n">n_x</span><span class="p">)</span><span class="o">*</span><span class="n">n_y</span>

    <span class="c1"># CASE cell_pos is a vector of vectors</span>
    <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">cell_pos</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span><span class="o">==</span><span class="mi">2</span><span class="p">:</span>
      <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__d</span><span class="o">==</span><span class="mi">2</span><span class="p">:</span>
        <span class="n">n_x</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__n_cells</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">cell_idx</span> <span class="o">=</span> <span class="n">cell_pos</span><span class="p">[:,</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="n">cell_pos</span><span class="p">[:,</span><span class="mi">1</span><span class="p">]</span><span class="o">*</span><span class="n">n_x</span>
      <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">__d</span><span class="o">==</span><span class="mi">3</span><span class="p">:</span>
        <span class="n">n_x</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__n_cells</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">n_y</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__n_cells</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
        <span class="n">cell_idx</span> <span class="o">=</span> <span class="n">cell_pos</span><span class="p">[:,</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="p">(</span><span class="n">cell_pos</span><span class="p">[:,</span><span class="mi">1</span><span class="p">]</span><span class="o">+</span><span class="n">cell_pos</span><span class="p">[:,</span><span class="mi">2</span><span class="p">]</span><span class="o">*</span><span class="n">n_x</span><span class="p">)</span><span class="o">*</span><span class="n">n_y</span>

    <span class="k">return</span> <span class="n">cell_idx</span>

  <span class="k">def</span> <span class="nf">__Unstack</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cell_idx</span><span class="p">):</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__d</span><span class="o">==</span><span class="mi">2</span><span class="p">:</span>
      <span class="n">n_x</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__n_cells</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
      <span class="n">y</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">cell_idx</span><span class="o">/</span><span class="n">n_x</span><span class="p">)</span>
      <span class="n">x</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">cell_idx</span><span class="o">-</span><span class="n">y</span><span class="o">*</span><span class="n">n_x</span><span class="p">)</span>
      <span class="n">cell_pos</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">])</span>
    <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">__d</span><span class="o">==</span><span class="mi">3</span><span class="p">:</span>
      <span class="n">n_x</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__n_cells</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
      <span class="n">n_y</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__n_cells</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
      <span class="n">z</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">cell_idx</span><span class="o">/</span><span class="p">(</span><span class="n">n_x</span><span class="o">*</span><span class="n">n_y</span><span class="p">))</span>
      <span class="n">y</span> <span class="o">=</span> <span class="nb">int</span><span class="p">((</span><span class="n">cell_idx</span><span class="o">-</span><span class="n">z</span><span class="o">*</span><span class="n">n_x</span><span class="o">*</span><span class="n">n_y</span><span class="p">)</span><span class="o">/</span><span class="n">n_x</span><span class="p">)</span>
      <span class="n">x</span> <span class="o">=</span> <span class="nb">int</span><span class="p">((</span><span class="n">cell_idx</span><span class="o">-</span><span class="n">z</span><span class="o">*</span><span class="n">n_x</span><span class="o">*</span><span class="n">n_y</span><span class="o">-</span><span class="n">y</span><span class="o">*</span><span class="n">n_x</span><span class="p">))</span>
      <span class="n">cell_pos</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">z</span><span class="p">])</span>
    <span class="k">return</span> <span class="n">cell_pos</span>

  <span class="k">def</span> <span class="nf">__AddNeighbors</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pos_t</span><span class="p">,</span> <span class="n">particles_in_cell</span><span class="p">,</span> <span class="n">R_c</span><span class="p">,</span> <span class="n">shift</span><span class="p">,</span>\
        <span class="n">cell_idx</span><span class="p">,</span> <span class="n">neigh_cell_idx</span><span class="p">):</span>
    <span class="n">n_p_cell</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">particles_in_cell</span><span class="p">[</span><span class="n">cell_idx</span><span class="p">])</span>
    <span class="n">n_p_neigh_cell</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">particles_in_cell</span><span class="p">[</span><span class="n">neigh_cell_idx</span><span class="p">])</span>

    <span class="k">for</span> <span class="n">p_cell</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">n_p_cell</span><span class="p">):</span>
      <span class="c1"># Particle index</span>
      <span class="n">p</span> <span class="o">=</span> <span class="n">particles_in_cell</span><span class="p">[</span><span class="n">cell_idx</span><span class="p">][</span><span class="n">p_cell</span><span class="p">];</span>

      <span class="c1"># Ensures no double counting</span>
      <span class="k">if</span><span class="p">(</span><span class="n">cell_idx</span><span class="o">==</span><span class="n">neigh_cell_idx</span><span class="p">):</span>
        <span class="n">n_p_neigh_cell</span> <span class="o">=</span> <span class="n">p_cell</span>

      <span class="k">for</span> <span class="n">p_neigh_cell</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">n_p_neigh_cell</span><span class="p">):</span>
        <span class="c1"># Neighboring particle index</span>
        <span class="n">p_neigh</span> <span class="o">=</span> <span class="n">particles_in_cell</span><span class="p">[</span><span class="n">neigh_cell_idx</span><span class="p">][</span><span class="n">p_neigh_cell</span><span class="p">]</span>

        <span class="n">r_vec</span> <span class="o">=</span> <span class="n">pos_t</span><span class="p">[</span><span class="n">p</span><span class="p">]</span><span class="o">-</span><span class="p">(</span><span class="n">pos_t</span><span class="p">[</span><span class="n">p_neigh</span><span class="p">]</span><span class="o">+</span><span class="n">shift</span><span class="p">)</span>
        <span class="n">sq_sum</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">r_vec</span><span class="o">*</span><span class="n">r_vec</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">sq_sum</span><span class="o">&lt;</span><span class="bp">self</span><span class="o">.</span><span class="n">__R_c_2</span><span class="p">:</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">__n_list_t</span><span class="p">[</span><span class="n">p</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p_neigh</span><span class="p">)</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">__n_list_t</span><span class="p">[</span><span class="n">p_neigh</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>

  <span class="k">def</span> <span class="nf">__AddCellPos</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cell_pos</span><span class="p">,</span> <span class="n">cell_delta</span><span class="p">,</span> <span class="n">bb_t</span><span class="p">,</span> <span class="n">bc</span><span class="p">):</span>
    <span class="n">neigh_cell_pos</span> <span class="o">=</span> <span class="n">cell_pos</span> <span class="o">+</span> <span class="n">cell_delta</span>
    <span class="n">shift</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__d</span><span class="p">)</span>
    <span class="n">are_neighbors</span> <span class="o">=</span> <span class="kc">True</span>
    <span class="k">for</span> <span class="n">dd</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__d</span><span class="p">):</span> 
      <span class="k">if</span> <span class="n">bc</span><span class="p">[</span><span class="n">dd</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;p&#39;</span><span class="p">:</span> 
        <span class="k">if</span> <span class="n">neigh_cell_pos</span><span class="p">[</span><span class="n">dd</span><span class="p">]</span><span class="o">==-</span><span class="mi">1</span><span class="p">:</span>
          <span class="n">neigh_cell_pos</span><span class="p">[</span><span class="n">dd</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__n_cells</span><span class="p">[</span><span class="n">dd</span><span class="p">]</span><span class="o">-</span><span class="mi">1</span>
          <span class="n">shift</span><span class="p">[</span><span class="n">dd</span><span class="p">]</span> <span class="o">=</span> <span class="n">bb_t</span><span class="p">[</span><span class="n">dd</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">-</span><span class="n">bb_t</span><span class="p">[</span><span class="n">dd</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span>
        <span class="k">elif</span> <span class="n">neigh_cell_pos</span><span class="p">[</span><span class="n">dd</span><span class="p">]</span><span class="o">==</span><span class="bp">self</span><span class="o">.</span><span class="n">__n_cells</span><span class="p">[</span><span class="n">dd</span><span class="p">]:</span>
          <span class="n">neigh_cell_pos</span><span class="p">[</span><span class="n">dd</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
          <span class="n">shift</span><span class="p">[</span><span class="n">dd</span><span class="p">]</span> <span class="o">=</span> <span class="n">bb_t</span><span class="p">[</span><span class="n">dd</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="n">bb_t</span><span class="p">[</span><span class="n">dd</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
      <span class="k">else</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">neigh_cell_pos</span><span class="p">[</span><span class="n">dd</span><span class="p">]</span><span class="o">==-</span><span class="mi">1</span> <span class="ow">or</span> \
              <span class="n">neigh_cell_pos</span><span class="p">[</span><span class="n">dd</span><span class="p">]</span><span class="o">==</span><span class="bp">self</span><span class="o">.</span><span class="n">__n_cells</span><span class="p">[</span><span class="n">dd</span><span class="p">]:</span>
          <span class="n">are_neighbors</span> <span class="o">=</span> <span class="kc">False</span>

    <span class="k">return</span> <span class="p">(</span><span class="n">are_neighbors</span><span class="p">,</span> <span class="n">neigh_cell_pos</span><span class="p">,</span> <span class="n">shift</span><span class="p">)</span></div>





















</pre></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">RSoft 1.0 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="index.html" >Module code</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2019, Robert Ivancic.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.8.5.
    </div>
  </body>
</html>